using System;
using System.IO;
using System.Collections.Generic;
using System.Text;

namespace MyMedia.iPod.Music
{
	public class TrackList : Node
	{
		int m_songCount;
		internal Mhlt m_mhlt;

		public int SongCount
		{
			get { return m_songCount; }
		}

		internal override void AddChild(Node node)
		{
			base.AddChild(node);

			Database.RegisterNode(node as TrackItem);
		}

		internal void AddSong(TrackItem item)
		{
			base.AddChild(item);

			m_mhlt.SongCount++;
		}

		//protected override int Size
		//{
		//    get { return m_mhlt.HeaderLength; }
		//}

		protected override void ReadImpl(BinaryReader reader)
		{
			m_mhlt = new Mhlt();
			m_mhlt.Read(reader);

			m_songCount = m_mhlt.SongCount;

			for (int i = 0; i < m_mhlt.SongCount; i++)
			{
				TrackItem item = new TrackItem();
				
				// The order here is important. Load first then AddChild
				item.Read(reader);
				AddChild(item);
			}
		}

		protected override void WriteImpl(BinaryWriter writer)
		{
			m_mhlt.Write(writer);
		}

		protected override void SetSize(int size) 
		{
		}
	}
}
